<!doctype html><html><head>
    <title>A canvas lineCap example</title>
    <meta name="DC.creator" content="Kamiel Martinet, http://www.martinet.nl/">
    <meta name="DC.publisher" content="Mozilla Developer Center, http://developer.mozilla.org">

<script src="../canvas.vml.js"></script>
<script src="../canvas.js"></script>

<script>
function oncanvasready() {
    drawShape(document.getElementById('vmlcanvas'));
}
function matrix() {
    drawShape(document.getElementById('vmlcanvas'), 1);
}

var globalAlpha = 1.0
function switchAlpha() {
    globalAlpha -= 0.2;
    drawShape(document.getElementById('vmlcanvas'));
}

var lineWidth = 1.0
function switchLineWidth() {
    lineWidth += 2;
    drawShape(document.getElementById('vmlcanvas'));
}

function drawShape(canvas, matrix){
    if (!canvas.getContext){ return; }

    var ctx = canvas.getContext('2d');

    ctx.clear();
    if (matrix) {
        ctx.translate(-10, 5);
        ctx.scale(1.2, 0.8);
        ctx.rotate(5 * Math.PI / 180);
    }
    ctx.globalAlpha = globalAlpha;
    ctx.lineWidth = lineWidth;

    var lineCap = ['butt','round','square'];

    // Draw guides
    ctx.strokeStyle = '#09f';
    ctx.beginPath();
    ctx.moveTo(10,20);
    ctx.lineTo(140,20);
    ctx.moveTo(10,130);
    ctx.lineTo(140,130);
    ctx.stroke();

    // Draw lines
    ctx.strokeStyle = 'black';
    ctx.lineWidth += 15;
    for (var i=0;i<lineCap.length;i++){
        ctx.lineCap = lineCap[i];
        ctx.beginPath();
        ctx.moveTo(25+i*50,20);
        ctx.lineTo(25+i*50,130);
        ctx.stroke();
    }
}
</script>
    <style type="text/css">
      body { margin: 20px; font-family: arial,verdana,helvetica; background: #fff;}
      h1 { font-size: 140%; font-weight:normal; color: #036; border-bottom: 1px solid #ccc; }
      canvas { float: left; margin-right: 20px; margin-bottom: 20px; }
      pre { float:left; display:block; background: rgb(238,238,238); border: 1px dashed #666; padding: 15px 20px; margin: 0 0 10px 0; }
    </style>
  </head>
  <body>
    <h1>A canvas <code>lineCap</code> example</h1>
    <div>
      <input type="button" value="matrix effect" onclick="matrix()" />
      <input type="button" value="alpha -0.2" onclick="switchAlpha()" />
      <input type="button" value="lineWidth +2" onclick="switchLineWidth()" />
      <br />
      <canvas id="vmlcanvas" class="vml" width="150" height="150"></canvas>
      <pre>
function oncanvasready() {
    drawShape(document.getElementById('vmlcanvas'));
}
function matrix() {
    drawShape(document.getElementById('vmlcanvas'), 1);
}

var globalAlpha = 1.0
function switchAlpha() {
    globalAlpha -= 0.2;
    drawShape(document.getElementById('vmlcanvas'));
}

var lineWidth = 1.0
function switchLineWidth() {
    lineWidth += 2;
    drawShape(document.getElementById('vmlcanvas'));
}

function drawShape(canvas, matrix){
    if (!canvas.getContext){ return; }

    var ctx = canvas.getContext('2d');

    ctx.clear();
    if (matrix) {
        ctx.translate(-10, 5);
        ctx.scale(1.2, 0.8);
        ctx.rotate(5 * Math.PI / 180);
    }
    ctx.globalAlpha = globalAlpha;
    ctx.lineWidth = lineWidth;

    var lineCap = ['butt','round','square'];

    // Draw guides
    ctx.strokeStyle = '#09f';
    ctx.beginPath();
    ctx.moveTo(10,20);
    ctx.lineTo(140,20);
    ctx.moveTo(10,130);
    ctx.lineTo(140,130);
    ctx.stroke();

    // Draw lines
    ctx.strokeStyle = 'black';
    ctx.lineWidth += 15;
    for (var i=0;i<lineCap.length;i++){
        ctx.lineCap = lineCap[i];
        ctx.beginPath();
        ctx.moveTo(25+i*50,20);
        ctx.lineTo(25+i*50,130);
        ctx.stroke();
    }
}
      </pre>
    </div>
  </body>
</html>
